SCE Digital Image Processing 2 - 20.12.2020
Benny Aman 205873599
עד מתי להגיש את העבודה :
You have to post it to the Moodle Box which is going to be opened in the Moodle Adress of the Course before 31.12.2020.
Enjoy your work
How to send your work
- Submit your work in the Moodle Assignment Box : Assignment 2 _2020_DigitalImageProcessing in the Moodle site of the Course.
- This is an open-book Assignment, which means you may consult lecture notes, internet resources and other ressources.
- You can do the Assignment by 2 (and no more please) , but do not share your Assignment to other groups. Indeed, Copy/Paste of entire answer from internet is not permitted. Please give answers in your own words.
- This Assignment will take you an estimated time of 4.0 hours
Next bohan
- the bohan is reported to December 3th, 2020 - program will be given latter.
Aim of the Assignment
This assignment comprised two parts:
Part 1: exercise on Chaps 3 and 4 - Filtering in Frequency Domain
- Remove the noise from the input images:
- Q3_1_1.tif
- Q3_1_2.tif
- Q3_1_3.tif
- Q3_1_4.tif
2. Submit your code and the output images.
נשתמש במסנן מסוג מדיאן שלפי ההרצאה הוא הטוב ביותר עבור סינון רעשים
a = imread("Q3_1_1.tif");
figure,imshow(a),title(' Original Q3_1_1 Image')
figure,imshow(A,[Min_A Max_A]),title('Image Q3_1_1 after Median Filter')
imwrite(A,'Q3_1_1_Median.tif');
b = imread('Q3_1_2.tif');
figure,imshow(b),title('Original Q3_1_2 Image')
figure,imshow(B,[Min_B Max_B]),title('Image Q3_1_2 after Median Filter')
imwrite(B,'Q3_1_2_Median.tif');
c = imread('Q3_1_3.tif');
figure,imshow(c),title('Original Q3_1_3 Image')
figure,imshow(C,[Min_C Max_C]),title('Image Q3_1_3 after Median Filter')
imwrite(C,'Q3_1_3_Median.tif');
d = imread("Q3_1_4.tif");
figure,imshow(d),title('Original Q3_1_4 Image')
figure,imshow(D,[Min_D Max_D]),title('Image Q3_1_4 after Median Filter')
imwrite(D,'Q3_1_4_Median.tif');
Part 2: restoring corrupted images using the Frequency Domain
צריך לעשות התמרת פורייה הפוכה מצגת 4ב שקופית 8
We will make Inverse Fourier Transform
- Restore the original images from the inputs
- Q3_2_1.tif
- Q3_2_2.tif
- Q3_2.3.tif
I = im2double(imread('Q3_2_3.tif'));
title('Original Image (courtesy of MIT)');
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
blurred_noisy = imnoise(blurred, 'gaussian', ...
figure, imshow(blurred_noisy)
title('Simulate Blur and Noise')
Part 3: Enhancing low-quality image using high pass filter.
2. Implement the whole procedure listed on the page 43 of the lecture 4 (see also all the section on High Pass Filter). Submit your code and output image. The input image is Q3_4.tif
לנסות לשים מטריצה שמחדדת
השקף המדובר מתוך ההרצאה
figure,imshow(I),title('The digital image section')
Now we will resizing the image to 50% of its original size
figure,imshow(I1),title('Re-Sampling')
Now we will blurring the Original Image with 3 X 3 averaging filter
D=fspecial('average',[3,3]); %exact 3 X 3 average filter
figure,imshow(d);title('3 X 3 average filter',"FontSize",15);
figure,imshowpair(I,d,'montage')
title('Original Image vs Image after Averaging filter',"FontSize",15)
אופציה שנייה - לא בטוח שנכון
%blurredImage = imfilter(I, ones(3)/27, 'symmetric');
%figure,imshow(blurredImage);
%title('Blurred Image', 'FontSize', 15);
Part 4:
- Step1: Create a 512×512 pixel image.
figure,imshow(p),title('512x512 pixel image');
- Step2: Assume that X and Y are the coordinates of pixels in the above image. Calculate the value of each pixel using the following equation:
לקחת תמונה להוסיף את הסינוס ואז לחזור עם התמרת פורייה
הסינוס זה רעש
Show your image.
z = sin(0.1.*x)+cos(0.4.*x)+sin(0.15*(x.^2+y.^2))+sin(0.35*(x.^2+y.^2));
figure,imshow(w,[]),title('Image with noise')
figure,imshowpair(P,w,'montage')
title('Original vs Noisy Image',"FontSize",15)
- Step3: Compute the Discrete Fourier Transform of this image. And show the magnitude and phase of DFT for this image. You can use MATLAB functions to calculate the DFT. You should rearrange the result to show the zero frequency in the center of the image. For this purpose, you can use “fftshift” function in MATLAB.
figure,imshow(log(abs(fftshift(Image_fft)+1)),[])
title('Magnitude of DFT')
figure, imshow(angle(fftshift(Image_fft)),[-pi pi])
- Step4: Multiply the magnitude of DFT by 2.0 and calculate the inverse Discrete Fourier Transform of it and show the result and explain the difference between the first image that you created in step 2 with this image.
figure,imshow(2.*log(abs(fftshift(Image_fft)+1)),[])
title('Magnitude multiply by 2 of DFT')
Now We calculate the inverse fft
back_to_Image=ifft2(Image_fft);
Image_min = min(min(abs(back_to_Image)));
Image_max = max(max(abs(back_to_Image)));
figure, imshow(abs(back_to_Image), [Image_min Image_max])
title('Image after inverse Discrete Fourier Transform')
figure,imshowpair(w,back_to_Image,'montage')
title(' Step 2 Image vs IDFT Image',"FontSize",15)
Part 5:
לקחת תמונה ולבצע בה תהליך עם נוצ' פילטר
A band-stop filter is a filter that passes most frequencies, but attenuates those in a specific range to very low levels. A notch filter is a band-stop filter with a narrow stopband. These filters are using to remove periodic noise that can be approximated as two-dimensional sinusoidal functions from the image.
For example, in the above figure at left you can see the satellite image of Florida showing horizontal scan lines, and at right you can see the result of applying a notch filter.
Use similar images and try to develop your own band-stop filter to remove the noise. For this purpose, you should calculate the DFT of the image and remove a specific range of frequencies and then calculate the inverse DFT. You need to test different frequency intervals to find the best filter.
footBall=imread('noiseball.png');
imshow(footBall),title('Our Image')
Determine good padding for Fourier transform
PQ = paddedsize(size(footBall));
Create Notch filters corresponding to extra peaks in the Fourier transform
H1 = notch('btw', PQ(1), PQ(2), 10, 50, 100);
H2 = notch('btw', PQ(1), PQ(2), 10, 1, 400);
H3 = notch('btw', PQ(1), PQ(2), 10, 620, 100);
H4 = notch('btw', PQ(1), PQ(2), 10, 22, 414);
H5 = notch('btw', PQ(1), PQ(2), 10, 592, 414);
H6 = notch('btw', PQ(1), PQ(2), 10, 1, 114);
Calculate the discrete Fourier transform of the image
F=fft2(double(footBall),PQ(1),PQ(2));
Apply the notch filters to the Fourier spectrum of the image
FS_football = F.*H1.*H2.*H3.*H4.*H5.*H6;
convert the result to the spacial domain
F_football=real(ifft2(FS_football));
Crop the image to undo padding
F_football=F_football(1:size(footBall,1), 1:size(footBall,2));
Display the Fourier Spectrum
Move the origin of the transform to the center of the frequency rectangle
Fcf=fftshift(FS_football);
use abs to compute the magnitude and use log to brighten display
figure, imshow(S1,[]),title('Fourier Spectrum of Image')
figure, imshow(S2,[]),title('Spectrum of image after Butterworth notch filters')
Display the blurred image
figure, imshow(F_football,[]),title('Image after notch filter')
הפונקציות שלנו שעזרו לפתרון התרגיל
function PQ = paddedsize(AB, CD, PARAM)
elseif nargin == 2 & ~ischar(CD)
m = max(AB); % Maximum dimension.
% Find power-of-2 at least twice m.
m = max([AB CD]); %Maximum dimension.
error('Wrong number of inputs.')
function H = notch(type, M, N, D0, x, y, n)
n = 1; % Default value of n.
% Generate highpass filter.
Hlp = lpfilter(type, M, N, D0, n);
H = circshift(H, [y-1 x-1]);
function H = lpfilter(type, M, N, D0, n)
% computing the required distances.
% Compute the distances D(U, V).
% Begin fiter computations.
H = 1./(1 + (D./D0).^(2*n));
H = exp(-(D.^2)./(2*(D0^2)));
error('Unknown filter type.')
function [U, V] = dftuv(M, N)
%DFTUV Computes meshgrid frequency matrices.
% Set up range of variables.
% Compute the indices for use in meshgrid
% Compute the meshgrid arrays
How to write your project:
- Your report should contain a brief overview of the problem, the details of your approach, and the results of your algorithm
- Show the results of all of the main steps
- You can submit your report using the live script or create a folder with the different code and a report in word/latex file in : Assignment 2 _2020_DigitalImageProcessing in the Moodle site of the Course.